import React from 'react'
import { useDispatch,useSelector } from 'react-redux'
import {increment,decrement} from '../../store/slice/countSlice'
export default function Count() {  
    //新的方法 react-redux中的dispatch
    const dispatch = useDispatch()
    //新的方法 react-redux 中的useSelector
    const count = useSelector(state=>state.count.count)
    const movieList = useSelector(state=>state.movie.movieList)


    const incrementHandle = ()=>{
        //改变这个值
        dispatch(increment(10))
    }

    const decrementHandle = ()=>{
        dispatch(decrement(3))
    }

    const ifOddDecrementHandle = ()=>{
        if(count%2!==0){
            dispatch(increment(1))
        }
    }

    const waitDecrementHandle = ()=>{

    }


  return (
    <div>
        <h1>我是Count组件 我的值是{count}</h1>
        <h4>当前的电影总数是多少{movieList.length}</h4>
        <button onClick={incrementHandle}>累加</button>
        <button onClick={decrementHandle}>累减</button>
        <button onClick={ifOddDecrementHandle}>当是奇数的时候加1</button>
        <button onClick={waitDecrementHandle}>2秒之后加1</button>
    </div>
  )
}
